<?php
$book = $_GET['book'];
$fromer = $_GET['fromer'];
?>
 <link href="/ast/layui/css/layui.css" rel="stylesheet">
<div class="layui-form" lay-filter="filter-test-layer" style="margin: 16px;">
            <div class="demo-login-container">
              <div class="layui-form-item">
                <div class="layui-input-wrap">
                <textarea id="booktalk" lay-verify="required" placeholder="写写看您对这本书的看法！(🈲脏话，侮辱性词语)" lay-reqtext="不能不填哦" autocomplete="off" class="layui-textarea" lay-affix="clear">
</textarea>
                </div>
              </div>
              <div class="layui-form-item">
                <button class="layui-btn layui-btn-fluid" id='button-add'  lay-submit lay-filter="addcard">Add</button>
              </div>
             
            </div>
          </div>
          <script src="/ast/layui/layui.js"></script>
<script>
layui.use('form', function(){
  var form = layui.form;
  var layer = layui.layer;
  form.render();
  return false;
});
var bookn = "<?php echo $book; ?>";
var fromer = "<?php echo $fromer; ?>";
function fetchcardadd(){
    const booktalk = document.getElementById('booktalk').value;
    if(booktalk === ''){
        layer.msg('请填写完整信息', {icon: 5});
        return false;
    }
    var loadingz = layer.load(2);
    fetch('/book/opinion.php',{
    method: 'POST',
            headers: {
                'Content-Type': 'application/json; charset=utf-8'
            },
            body: JSON.stringify({
                book: bookn,
                from: fromer,
                talk:booktalk
            })
        }).then(response => response.json())
        .then(data => {
        layer.close(loadingz);
        if(data.code === 200){
            layer.msg(data.msg, {icon: 6});
        }else{
            layer.msg(data.msg, {icon: 5});
        }
        setTimeout(function(){
            window.parent.location.reload();
        }, 1000);
    })
}
document.getElementById('button-add').addEventListener('click', fetchcardadd)
</script>
<script language="javascript" type="text/javascript">
    if (window.self == window.top) {
        alert("暂无通行证");
        location.href = "./";
    }
</script>